home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- ** **
- ** Module: SetupPickPoint.c **
- ** **
- ** **
- ** Purpose: **
- ** **
- ** **
- ** **
- ** Copyright (C) 1992-1995 Apple Computer, Inc. All rights reserved. **
- ** **
- ** Change Log: **
- ** **
- ** 01/21/94 pjs Fixed picking. **
- ** **
- *****************************************************************************/
- #include "QD3D.h"
- #include "SetupPickPoint.h"
- #include "QD3DMath.h"
- #include "QD3DCamera.h"
-
-
-
- /*===========================================================================*\
- *
- * Routine: SetupPickPoint()
- *
- * Comments:
- *
- \*===========================================================================*/
-
- void SetupPickPoint(
- WindowPtr qdWindow,
- TQ3Point2D *pickPoint,
- TQ3CameraObject camera,
- TQ3Point2D *screenPoint)
- {
- float xf, yf;
- Rect r;
- short width, height;
- TQ3RationalPoint4D worldPoint, localPoint;
- TQ3Matrix4x4 wtfmatrix;
- TQ3Point3D camFrom;
- TQ3CameraPlacement camPlacementData;
-
- pickPoint; /* unused argument */
- screenPoint; /* unused argument */
-
- r = qdWindow->portRect;
- width = r.right - r.left;
- height = r.bottom - r.top;
-
- xf = 0.0; /* Julian, you have a bug here. I've added these two lines */
- yf = 0.0; /* but you will need to change them to the appropriate */
- /* values 5/15/94 brh */
-
- /* move from 0 to 1 skiashape space to -1 to 1 frustum space. */
- localPoint.x = xf * 2.0 - 1.0;
- localPoint.y = (1.0 - yf) * 2.0 - 1.0; /* invert y */
- localPoint.z = 0.0;
- localPoint.w = 1.0;
-
- Q3Camera_GetWorldToFrustum(camera, &wtfmatrix);
- Q3Matrix4x4_Invert(&wtfmatrix, &wtfmatrix);
-
- Q3RationalPoint4D_To4DTransformArray(&localPoint,
- &wtfmatrix,
- &worldPoint,
- 1,
- sizeof(TQ3Point3D),
- sizeof(TQ3Point3D));
-
- worldPoint.x /= worldPoint.w;
- worldPoint.y /= worldPoint.w;
- worldPoint.z /= worldPoint.w;
-
-
- Q3Camera_GetPlacement(camera, &camPlacementData);
-
- camFrom = camPlacementData.cameraLocation;
-
- Q3Vector3D_Normalize((TQ3Vector3D *)&camFrom, (TQ3Vector3D *)&camFrom);
- }
-